home *** CD-ROM | disk | FTP | other *** search
/ Merciful 1 / Merciful - Disc 1.iso / software / g / gvp_faaast_prep / gvpfaastprep.dms / gvpfaastprep.adf / ScsiExamples / ScsiExamples.lzh / Inquiry.c < prev    next >
C/C++ Source or Header  |  1990-07-05  |  3KB  |  156 lines

  1. /*
  2. ** Inquiry.c - get identification from hard drive using HD_SCSICMD
  3. ** Copyright (C) 1988 by Ralph Babel, Falkenweg 3, D-6204 Taunusstein, FRG
  4. ** all rights reserved - alle Rechte vorbehalten
  5. **
  6. ** 25-Oct-1988 created
  7. */
  8.  
  9. /*** included files ***/
  10.  
  11. #include <exec/types.h>
  12. #include <exec/io.h>
  13. #include <exec/memory.h>
  14. #include <devices/scsidisk.h>
  15. #include <libraries/dos.h>
  16. #include <proto/exec.h>
  17. #include <proto/dos.h>
  18.  
  19. /*** external symbol references ***/
  20.  
  21. void fprintf(BPTR, const char *, ...);
  22.  
  23. /*** constants ***/
  24.  
  25. #define BOARD 0 /* controller board */
  26. #define TID   0 /* SCSI target ID */
  27. #define LUN   0 /* logical unit */
  28.  
  29. #define UNIT (BOARD * 100 + LUN * 10 + TID)
  30.  
  31. #define MAXBUF 252
  32.  
  33. /*** entry point (RXStartUp.obj) ***/
  34.  
  35. void __stdargs __saveds main(
  36. ULONG argc,
  37. const char *const argv[])
  38.  {
  39.  BPTR fh;
  40.  UBYTE *scsidata;
  41.  UBYTE *sensedata;
  42.  struct MsgPort *mp;
  43.  struct IOStdReq *io;
  44.  struct SCSICmd SC;
  45.  UBYTE command[6];
  46.  UWORD i;
  47.  
  48.  if(argc != 0) /* CLI only! */
  49.   {
  50.   fh = Output();
  51.  
  52.   if((scsidata = AllocMem(MAXBUF, MEMF_CHIP)) != NULL)
  53.    {
  54.    if((sensedata = AllocMem(MAXBUF, MEMF_CHIP)) != NULL)
  55.     {
  56.     if((mp = CreatePort(NULL, 0)) != NULL)
  57.      {
  58.      if((io = CreateStdIO(mp)) != NULL)
  59.       {
  60.       if(OpenDevice("gvpscsi.device", UNIT, (struct IORequest *)io, 0) == 0)
  61.        {
  62.        io->io_Command = HD_SCSICMD;
  63.        io->io_Length  = sizeof(struct SCSICmd);
  64.        io->io_Data    = (APTR)&SC;
  65.  
  66.        SC.scsi_Data        = (UWORD *)scsidata;
  67.        SC.scsi_Length      = MAXBUF;
  68.        SC.scsi_Command     = command;
  69.        SC.scsi_CmdLength   = 6;
  70.  
  71. #ifdef SCSIF_AUTOSENSE
  72.  
  73.        SC.scsi_Flags       = SCSIF_READ | SCSIF_AUTOSENSE;
  74.        SC.scsi_SenseData   = sensedata;
  75.        SC.scsi_SenseLength = MAXBUF;
  76.        SC.scsi_SenseActual = 0;
  77.  
  78. #else
  79.  
  80.        SC.scsi_Flags       = SCSIF_READ;
  81.  
  82. #endif
  83.  
  84.        command[0] = 0x12; /* INQUIRY */
  85.        command[1] = LUN << 5;
  86.        command[2] = 0;
  87.        command[3] = 0;
  88.        command[4] = MAXBUF;
  89.        command[5] = 0;
  90.  
  91.        (void)DoIO((struct IORequest *)io);
  92.  
  93.        fprintf(fh, "io_Error         = %d\n",  io->io_Error);
  94.        fprintf(fh, "scsi_Status      = %d\n",  SC.scsi_Status);
  95.        fprintf(fh, "scsi_CmdActual   = %d\n",  SC.scsi_CmdActual);
  96.        fprintf(fh, "scsi_Actual      = %ld\n", SC.scsi_Actual);
  97.  
  98. #ifdef SCSIF_AUTOSENSE
  99.  
  100.        fprintf(fh, "scsi_SenseActual = %d\n",  SC.scsi_SenseActual);
  101.  
  102.        if(SC.scsi_SenseActual != 0)
  103.         {
  104.         fprintf(fh, "\nSenseData:");
  105.  
  106.         for(i = 0; i < SC.scsi_SenseActual; ++i)
  107.          fprintf(fh, " %02x", sensedata[i]);
  108.  
  109.         fprintf(fh, "\n");
  110.         }
  111.  
  112. #endif
  113.  
  114.        if(io->io_Error == 0)
  115.         {
  116.         fprintf(fh, "\n");
  117.  
  118.         for(i = 0; i < 5; ++i)
  119.          fprintf(fh, "%d: $%02x\n", i, scsidata[i]);
  120.  
  121.         fprintf(fh, "\n");
  122.  
  123.         for(i = 5; i < SC.scsi_Actual; ++i)
  124.          fprintf(fh, "%c", scsidata[i] != 0? scsidata[i]: '.');
  125.  
  126.         fprintf(fh, "\n");
  127.         }
  128.  
  129.        CloseDevice((struct IORequest *)io);
  130.        }
  131.       else
  132.        fprintf(fh, "Error %d while opening SCSI unit %ld.\n",
  133.         io->io_Error, (long)UNIT);
  134.  
  135.       DeleteStdIO(io);
  136.       }
  137.      else
  138.       fprintf(fh, "Could not create I/O request.\n");
  139.  
  140.      DeletePort(mp);
  141.      }
  142.     else
  143.      fprintf(fh, "Could not create message port.\n");
  144.  
  145.     FreeMem(sensedata, MAXBUF);
  146.     }
  147.    else
  148.     fprintf(fh, "Insufficient free store.\n");
  149.  
  150.    FreeMem(scsidata, MAXBUF);
  151.    }
  152.   else
  153.    fprintf(fh, "Insufficient free store.\n");
  154.   }
  155.  }
  156.